package com.luguokong.pet_rescue.controller;

import com.luguokong.pet_rescue.pojo.Essay;
import com.luguokong.pet_rescue.service.EssayService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/essay")
public class EssayCtrl {
    @Autowired
    private EssayService essayService;

    @GetMapping("/getByPage")
    public List<Essay> selectEssayAllByPageNumByPageSize(int pageNum, int pageSize){
       List<Essay> essayList = essayService.selectEssayAllByPageNumByPageSize((pageNum-1)*pageSize, pageSize);
       return essayList;
    }

    @GetMapping("/getDataCount")
    public int selectDataCount(){
        int i = essayService.selectDataCount();
        return i;
    }


    @PostMapping("/insertEssay")
    public int insertEssay(@RequestBody Essay essay){
        int i = essayService.insertEssay(essay);
        return i;
    }

    @GetMapping("/deleteEssayById")
    public int deleteEssayById(int essayId){
        int i = essayService.deleteEssayById(essayId);
        return i;
    }

    @PostMapping("/updateEssayById")
    public int updateEssayById(@RequestBody Essay essay){
        int i = essayService.updateEssayById(essay);
        return i;
    }

    @PostMapping("/deleteEssayByArrId")
    public int deleteEssayByEssayIdArray(@RequestBody int [] essayIdArr){
        int i = essayService.deleteEssayByEssayIdArray(essayIdArr);
        return i;
    }

    //    查询近六个月按月分组的数据
    @GetMapping("/selectGroupByMonth")
    public List<Map<String, Number>> selectCountByRecentSixMGroupByMonth(){
        List<Map<String, Number>> mapList = essayService.selectCountByRecentSixMGroupByMonth();
        return mapList;
    }

}
